package at.guigu.config;

import at.guigu.interceptor.MyInterceptor;
import at.guigu.interceptor.MyInterceptorTwo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurationSupport;

// 配置静态资源以及拦截器的路径映射
@Configuration
public class SpringMvcSupport extends WebMvcConfigurationSupport {
    @Autowired
    private MyInterceptor myInterceptor;
    @Autowired
    private MyInterceptorTwo myInterceptorTwo;

    // 配置静态资源路径
    @Override
    protected void addResourceHandlers (ResourceHandlerRegistry registry) {
        // 配置静态资源路径映射
        registry.addResourceHandler("/xxx/**").addResourceLocations("/xxx/");
    }

    // 配置拦截器路径
    @Override
    protected void addInterceptors(InterceptorRegistry registry) {
        //addInterceptor定义拦截器的具体实现类
        //addPathPatterns的参数代表拦截所有请求路径
        registry.addInterceptor(myInterceptor).addPathPatterns("/**");
        registry.addInterceptor(myInterceptorTwo).addPathPatterns("/**");
    }
}